//
//  YCMonthEarnTableViewCell.m
//  lianganyuchu
//
//  Created by iMac on 17/2/24.
//  Copyright © 2017年 杭州桑缇电子商务有限公司. All rights reserved.
//

#import "YCMonthEarnTableViewCell.h"

@interface YCMonthEarnTableViewCell()
{
    UIView *m_detailView;
}
@end
@implementation YCMonthEarnTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    self.labBack.layer.cornerRadius=2.0f;
    [self.backView click:self action:@selector(clickBack:)];
    
    [self.label1 setFont:[UIFont LightFontOfSize:15]];
    [self.label1 setTextColor:TEXT_DEEP];
    [self.label2 setFont:[UIFont LightFontOfSize:15]];
    [self.label2 setTextColor:TEXT_DEEP];
    [self.labMonth setFont:[UIFont LightFontOfSize:15]];
    [self.labMonth setTextColor:TEXT_DEEP];
    
    [self.labTotal setFont:[UIFont LightFontOfSize:14]];
    [self.labTotal setTextColor:TEXT_MIDDLE];
    [self.labIncome setFont:[UIFont LightFontOfSize:14]];
    [self.labIncome setTextColor:TEXT_MIDDLE];
    [self.labExpand setFont:[UIFont LightFontOfSize:14]];
    [self.labExpand setTextColor:TEXT_MIDDLE];
    
    [self.label1 setHidden:YES];
    [self.label2 setHidden:YES];
    [self.labIncome setHidden:YES];
    [self.labExpand setHidden:YES];
    [self.arrowView1 setHidden:YES];
    [self.arrowView2 setHidden:YES];
    [self.labLine setHidden:YES];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
-(void)bindWith:(StatisticsYearTable *)statis
{
    _statis=statis;
    if (statis.selected) {
        CGFloat width=kMainScreen_Width-2*kDistance;
        if (statis.item.count>0) {
            [self.backView addShadowWith:CGSizeMake(width, 40+statis.item.count*40)];
        }
        
        if (statis.item.count>0) {
            if (m_detailView==nil) {
                m_detailView=[[UIView alloc]initWithFrame:CGRectMake(0, 40, width, statis.item.count*40)];
                
                for (int i=0; i<statis.item.count; i++) {
                    EarningItemView *itemView=[[EarningItemView alloc]initWithFrame:CGRectMake(0, i*40, width, 40)];
                    [itemView setDataWith:statis.item[i]];
                    
                    if (i<statis.item.count-1) {
                        [itemView.layer addSublayer:getLine(kDistance, width-kDistance, 40, 40, LINE_COLOR)];
                    }
                    itemView.tag=i;
                    [itemView click:self action:@selector(clickView:)];
                    [m_detailView addSubview:itemView];
                }
            }
            [self.backView addSubview:m_detailView];
            [m_detailView setHidden:NO];
        }
        
    }else{
        self.backView.layer.shadowPath=nil;
        [m_detailView setHidden:YES];
    }
    
    [self.labMonth setText:[NSString stringWithFormat:@"%@月",statis.month]];
    [self.labTotal setText:[NSString stringWithFormat:@"共计%@元",statis.amount]];
}

-(void)clickBack:(UIGestureRecognizer *)gesture
{
    CGFloat pointY=[gesture locationInView:gesture.view].y;
    if (pointY>40) {
        //self.detailBlock();
    }else{
        self.headerBlock();
    }
}
-(void)clickView:(UIGestureRecognizer *)gesture
{
    self.detailBlock(_statis.item[gesture.view.tag]);
}


@end
